package dialogs;

import java.awt.event.ActionEvent;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import controllers.AbstractController;
import controllers.CustomerLoginController;

@SuppressWarnings("serial")
public class CustomerLoginDialog extends AbstractGeneralPurposeDialog {
	
	CustomerLoginController controller;

	public CustomerLoginDialog(JFrame parent, AbstractController c) {
		super(parent, "Customer Login", "Login Credentials", 
				new String[] {"Customer ID", "Password"}, c);
		controller = (CustomerLoginController)c;
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		
		if (e.getActionCommand().equals("OK"))
		{
			int retCode = controller.validateLogin(text_fields.get(0).getText().trim(), 
					text_fields.get(1).getText().trim());
			if (retCode == VALIDATIONERROR)
				JOptionPane.showMessageDialog(this, "Please fill in all fields", "Error",
						JOptionPane.ERROR_MESSAGE);
			else if (retCode == OPERATIONFAILED)
				JOptionPane.showMessageDialog(this, "Customer ID and/or Password are invalid", "Error",
						JOptionPane.ERROR_MESSAGE);
			else 
				dispose();
		}
		
	}

}
